<?php


namespace app\apiadmin\model\system;


use app\apiadmin\model\choujiang\PrizeUserModel;
use think\facade\Db;
use think\Model;

class UserModel extends Model
{

    protected $name="siyu_user";

    protected $pk="id";
    
    public static function list()
    {
        return self::field('nickname as label,nickname as pinyin,id')->select()->toArray();
    }
    public static function getAllChouJiangUser($param)
    {
        $res_user = Db::name('siyu_prize_user')->alias('p')
                        ->join('xh_siyu_user u','u.id = p.user_id')
                        ->where('p.prid',$param['id'])
                        ->field('u.nickname as label,u.nickname as pinyin,u.id')
                        ->select()->toArray();
        $selectUserIds = [];
        if($res_user){
            $selectUserIds = array_column($res_user,'id');
        }
        $user_data = self::field('nickname as label,nickname as pinyin,id')->select()->toArray();
        $user_datas = [];
        if($user_data && $res_user){
            foreach ($user_data as $key=>$value){
                if(!in_array($value['id'],$selectUserIds)){
                    $user_datas[] = $value; 
                }
            }
        }
        
        return $user_datas;
    }
    public static function getEditChouJiangUser($param)
    {
        $res_user = Db::name('siyu_prize_user')->alias('p')
            ->join('xh_siyu_user u','u.id = p.user_id')
            ->where('p.prid',$param['id'])
            ->field('u.nickname as label,u.nickname as pinyin,u.id')
            ->select()->toArray();
        return $res_user;
    }
    /**
     * @param $model
     * @return mixed
     * 添加
     */
    public static function add($model)
    {
        $memberModel = new UserModel();
        $memberModel->save($model);
        return $memberModel->id;

    }
    public static function edit($param){

        self::update($param, ['id' => $param['id']]);
    }
    public static function findById($id)
    {
        return self::find($id);
    }

    public static function del($id)
    {
        self::destroy($id);
    }
    

}